<script setup lang="ts">
import { useSystemHook } from "@/hook/useSystem";
import { onPageScroll } from "@dcloudio/uni-app";
import { computed } from "vue";
const { allSystemSize } = useSystemHook();

interface Props {
  title?: string;
  titleOpacity?: number;
  isBack?:boolean
}

const props = withDefaults(defineProps<Props>(), {
  titleOpacity: 1,
  isBack:true
});

const titleStyle = computed(() => {
  return {
    height: allSystemSize.value.totalHeight + "px",
    paddingTop: allSystemSize.value.menuTop + "px",
    opacity: props.titleOpacity,
  };
});
const pageStyle = computed(() => {
  return {
    top: allSystemSize.value.menuTop + "px",
  };
});

const handleHome = () => {
  uni.switchTab({
    url: "/pages/index/index",
  });
};

const handleBack = () => {
  uni.navigateBack({
    delta: 1, // 返回上一级页面。
  });
};

</script>

<template>
  <div class="page-header" v-if="isBack" :style="pageStyle">
    <span class="page-header-item" @click="handleBack">
      <i class="iconfont icon icon-zuo"></i>
    </span>
    <span class="page-header-item" @click="handleHome">
      <i class="iconfont icon icon-jingqu1"></i>
    </span>
  </div>
  <div class="page-header-title" :style="titleStyle">{{ props?.title }}</div>
</template>

<style lang="scss" scoped>
.page-header-title {
  overflow: hidden;
  position: fixed;
  left: 0;
  top: 0;

  background-color: #fff;
  width: 100%;
  box-sizing: border-box;
  padding-top: 24px;
  line-height: 33px;
  text-align: center;
  z-index: 998;
}

.page-header {
  display: flex;
  border-radius: 100px;
  overflow: hidden;
  position: fixed;
  z-index: 999;
  left: 7px;
  top: 24px;
  border: 1px solid rgba($color: #000, $alpha: 0.1);
  padding: 0px 0;
  box-sizing: border-box;
  &-item {
    width: 44px;
    height: 31px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba($color: #fff, $alpha: 0.5);
    cursor: pointer;
    &:nth-child(n + 2) {
      border-left: 1px solid rgba($color: #000, $alpha: 0.1);
    }
    &:hover {
      background-color: #fff;
    }
  }
  .icon {
    font-size: 34rpx;
  }
}
</style>
@/hooks/useSystem